<link href="/css/pagination.css" media="all" rel="stylesheet" type="text/css" />
<style type="text/css">
#admin_memo { width: auto; margin: 20px 0px; } 
#admin_memo table tr th { text-align: center; background: #f7f7f7; }
#admin_memo table tr td { text-align: center; }
#admin_memo table tr td.left { text-align: left; }
#admin_memo table tr td a { color:#555; text-decoration: underline; background-color: transparent; }
#admin_memo table tr td a:hover { color:#ff0000; text-decoration: underline; }
</style>
<div id="admin_memo">
<h3>便笺列表</h3>
<table class="table table-bordered">
	<tr>
		<th>编号</th>
		<th>用户名称</th>
		<th>内容</th>
		<th>发布时间</th>
		<th>修改时间</th>
		<th>操作</th>
	</tr>
	<% @memolist.each do |memo| %>
	<tr>
		<td><%=memo.id%></td>
		<td><a href="./memolist?userid=<%=memo.userid%>"><%=memo.user.name%></a></td>
		<td style="text-align:left; width:450px; <%if(memo.isdeleted == 1)%>text-decoration: line-through<%end%>"><%=memo.content[0,80] %></td>
		<td<% if(Time.now.in_time_zone(+8.hours).strftime('%Y-%m-%d') == memo.created_at.in_time_zone(+8.hours).strftime('%Y-%m-%d')) %> style="background-color:#FFFFCC;"<% end %>>
		<%=memo.created_at.in_time_zone(+8.hours).strftime('%Y-%m-%d %H:%M:%S') %></td>
		<td<% if(Time.now.in_time_zone(+8.hours).strftime('%Y-%m-%d') == memo.updated_at.in_time_zone(+8.hours).strftime('%Y-%m-%d')) %> style="background-color:#FFFFCC;"<% end %>>
		<%=memo.updated_at.in_time_zone(+8.hours).strftime('%Y-%m-%d %H:%M:%S') %></td>
		<td><%if(memo.isdeleted == 1)%><a href="javascript:void(__delete(<%=memo.id%>));">删除</a>
			<%end%></td>
	</tr>
	<% end %>
</table>

<div class='flickr_pagination' style="text-align:left;"><%= will_paginate @memolist, :previous_label => '上页', :next_label => '下页' %></div>
</div>
<script type="text/javascript">


$().ready(function(){

	$.ajaxSetup({  
	    beforeSend: function(xhr) {  
	        xhr.setRequestHeader("X-CSRF-Token", $("meta[name=\"csrf-token\"]").attr("content"));  
	    }  
	});	


});

// 删除单条
function __delete(memoid) {
	if(confirm('确定要删除么?')) {
		$.ajax({
				type : 'POST',
				url : '/admin/memo/delete',
				data : { 'id' : memoid },
				success: function(d){
					if(d) {
						alert('已删除');
						location.href = location.href;
					} else {
						alert('删除失败，请重新尝试。');
					}
				}
			});
	}
}



</script>